package com.djzhou.gmms.service.email.impl;

import java.util.HashMap;
import java.util.List;

import com.djzhou.gmms.service.base.impl.BaseServiceImpl;
import com.djzhou.gmms.service.email.AttachmentService;
import com.djzhou.gmms.util.session.UserSession;
import com.djzhou.gmms.model.announcement.TbAnnouncement;
import com.djzhou.gmms.model.email.TbAttachment;
import com.djzhou.gmms.model.entity.PageBean;
import com.djzhou.gmms.model.user.VoResource;
import com.djzhou.util.DateUtil;

public class AttachmentServiceImpl extends BaseServiceImpl implements AttachmentService{

	@Override
	public void add(TbAttachment t) {
		attachmentDAO.insert(t);
	}

	@Override
	public void delete(Integer id) {
		attachmentDAO.delete(TbAttachment.class,id);
		
	}

	@Override
	public TbAttachment queryById(Integer id) {
		return attachmentDAO.queryByID(TbAttachment.class, id);
	}

	@Override
	public List<TbAttachment> queryList(HashMap<String, Object> hashMap) {
		return attachmentDAO.query("from TbAttachment");
	}

	@Override
	public PageBean<TbAttachment> queryPageBean(
			HashMap<String, Object> hashMap, int pageSize, int currentPage) {
		String hql="from TbAttachment  attachment where 1=1";
		StringBuffer sb=new StringBuffer();
		sb.append(hql);
		sb.append(" and (attachment.email.receiver.userId=").append(UserSession.getSessionModel().getUser().getUserId());
		sb.append(" or attachment.email.sender.userId=").append(UserSession.getSessionModel().getUser().getUserId()).append(")");
		sb.append(" order by attachment.attachmentId desc");
		hql=sb.toString();
		PageBean<TbAttachment> pageBean=attachmentDAO.selectByPage(hql, pageSize, currentPage);
		return pageBean;
	}

	@Override
	public void update(TbAttachment t) {
		attachmentDAO.update(t);
	}

	@Override
	public VoResource query4AutoComplete(HashMap<String, Object> hashMap, String sidx,
			String sord, int pageSize, int currentPage) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<TbAttachment> queryListByEmail(Integer emailId) {
		String hql="from TbAttachment  attachment where attachment.email.emailId=?";
		return attachmentDAO.query(hql, emailId);
	}
}
